package com.shopping.superDao.impl;

import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.springframework.jdbc.core.JdbcTemplate;

import com.shopping.superDao.SuperDao;
import com.shopping.util.DBUtil;

public class SuperDaoImpl implements SuperDao{

	JdbcTemplate jt = new JdbcTemplate(DBUtil.getDataSource());
	@Override
	public Map<String, Object> selectById(int id,String table,String findid) {
		String sql = "select * from ";
		sql += table +" where " +findid +" = " +id;
		Map<String,Object> map = jt.queryForMap(sql);
		return map;
	}

	@Override
	public List<Map<String,Object>> selectAll(String table) {
		String sql = "select * from ";
		sql += table;
		List<Map<String,Object>> map = jt.queryForList(sql);
		return map;
		
	}

	@Override
	public Map<String, Object> selectByName(String name, String table, String tableName) {
		String sql = "select * from ";
		sql += table + "where "+ tableName + " = " +name;
		Map<String,Object> map = jt.queryForMap(sql);
		return map;
	}

	@Override
	public Map<String,Object> analysis(List<Map<String,Object>> list) {
		Map<String,Object> map = null;
		for(int i = 0;i < list.size();i++ ) {
			Set<Entry<String,Object>> set = list.get(i).entrySet();
			for(Entry<String,Object> s:set) {
				map.put(s.getKey(), s.getValue());
			}
		}
		return map;
	}

	
}
